package com.nuanshui.framework.utils.json;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class Map2Json {
	
	/**
	 * 将map集合转换成json数据
	 * @author Gonzo
	 * @date 2016年11月23日上午11:12:23
	 * @param map
	 * @return
	 */
	public static String convertMap2JsonString(Map<String, Object> map){
		Set<Entry<String, Object>> set = map.entrySet();
		StringBuilder sb = new StringBuilder();
		sb.append("{");
		for(Entry<String, Object> entry : set){
			String key = entry.getKey();
			Object value = entry.getValue();
			sb.append("\""+key+"\"");
			sb.append(":\""+value+"\",");
		}
		String sbStr = sb.substring(0, sb.length()-1);
		sbStr = sbStr + "}";
		return sbStr;
	}
	
	
	public static void main(String[] args) {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("string1", "sadf");
		map.put("string2", "sadf");
		map.put("string3", "sadf");
		map.put("string4", "sadf");
		map.put("string5", "sadf");
		
		System.out.println(convertMap2JsonString(map));
		
		
	}
}
